/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Build")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Build.findAll", query = "SELECT b FROM Build b"),
    @NamedQuery(name = "Build.findByVillager", query = "SELECT b FROM Build b WHERE b.buildPK.villager = :villager"),
    @NamedQuery(name = "Build.findByBuilding", query = "SELECT b FROM Build b WHERE b.buildPK.building = :building"),
    @NamedQuery(name = "Build.findByAmount", query = "SELECT b FROM Build b WHERE b.amount = :amount")})
public class Build implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BuildPK buildPK;
    @Column(name = "amount")
    private Integer amount;
    @JoinColumn(name = "villager", referencedColumnName = "unit", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Villager villager1;
    @JoinColumn(name = "building", referencedColumnName = "unit", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Building building1;

    public Build() {
    }

    public Build(BuildPK buildPK) {
        this.buildPK = buildPK;
    }

    public Build(int villager, int building) {
        this.buildPK = new BuildPK(villager, building);
    }

    public BuildPK getBuildPK() {
        return buildPK;
    }

    public void setBuildPK(BuildPK buildPK) {
        this.buildPK = buildPK;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Villager getVillager1() {
        return villager1;
    }

    public void setVillager1(Villager villager1) {
        this.villager1 = villager1;
    }

    public Building getBuilding1() {
        return building1;
    }

    public void setBuilding1(Building building1) {
        this.building1 = building1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (buildPK != null ? buildPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Build)) {
            return false;
        }
        Build other = (Build) object;
        if ((this.buildPK == null && other.buildPK != null) || (this.buildPK != null && !this.buildPK.equals(other.buildPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Build[ buildPK=" + buildPK + " ]";
    }
    
}
